<?php
namespace app\command;


use app\model\ActivitiesModel;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Db;

class UpdateActiveStatus extends Command
{

    protected function configure()
    {
        $this->setName('更新正行活动状态')
            ->setDescription('更新正行活动状态');
    }

    protected function execute(Input $input, Output $output)
    {
        // 执行你的脚本任务代码
        // 查询
        $now = date('Y-m-d H:i:s');
        $where = [];
        $where["status"] = 1;
        $model = new ActivitiesModel();
        $list =   Db::name("activities")->where($where)->select();


        if($list){
            $list = $list->toArray();
            foreach ($list as $value){
                if($value["active_max_num"] != 0 && $value["active_current_num"] >= $value["active_max_num"]){
                    $model->updateStatus($value["active_id"],2);
                    $model->delCache($value["active_id"]);
                }elseif (strtotime($value["stop_time"]) <= time()){
                    $model->updateStatus($value["active_id"],2);
                    $model->delCache($value["active_id"]);
                }
            }
        }
    }
}